//
//  ViewController.m
//  KVC的实现
//
//  Created by webplus on 17/8/31.
//  Copyright © 2017年 sanyi. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"
#import "TwoTimesArray.h"
#import "ObersveArray.h"
#import "NSObject+MYKVC.h"
#import "Address.h"

static const NSString *nu;
@interface ViewController ()
@property (nonatomic,strong) Person *p1;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    Person* p = [Person new];
    [p setValue:@"newName" forKey:@"name"];
    [p setValue:nil forKey:@"age"];
    NSString* name = [p valueForKey:@"name"];
    NSString* age = [p valueForKey:@"age"];
    NSLog(@"%@",name);
    NSLog(@"%@",age);
    TwoTimesArray *t = [TwoTimesArray new];
    NSNumber *num = [t valueForKey:@"num"];
    NSLog(@"%@",num);
    id ar = [t valueForKey:@"numbers"];
    NSLog(@"%@----%@",NSStringFromClass([ar class]),ar);
    NSLog(@"0:%@     1:%@     2:%@     3:%@",ar[0],ar[1],ar[2],ar[3]);
    _p1 = [[Person alloc]init];
    int a = 10;
    p.age = 10;
    
    NSString *str = @"11";
    p.sex = @"2";
    _p1.sex = @"3";
    NSString *str1 = p.sex;
    NSArray *arr = @[@"1"];
    char *d = "23";
    NSLog(@"%p--%p---%p---%p---%p---%p---%p---%p---%p---%p",&a,p,str,arr,d,&nu,str1,p.sex,_p1,_p1.sex);
    
    
    ObersveArray *oby = [ObersveArray new];
    [oby addItem];
    [oby addItemObserver];
    [oby removeItemObserver];
    //第一个方法不响应，第二个第三个方法相应，调用mutableArrayValueForKey,因为mutableArrayKey会拷贝key内存地址发生变化,发出通知
    
    
    
    
    
    
    Address* add = [Address new];
    add.country = @"中国";
    add.province = @"河南";
    add.city = @"郑州";
    
    [add setMyValue:nil forKey:@"area"];            //测试设置 nil value
    [add setMyValue:@"USA" forKey:@"country"];
    [add setMyValue:@"GAOXIN" forKey:@"area"];
    [add setMyValue:@"475000" forKey:@"postCode"];
    
    NSLog(@"country:%@  province:%@ city:%@ postCode:%@",add.country,add.province,add.city,add.postCode);
    NSString* postCode = [add myValueforKey:@"postCode"];
    NSString* country = [add myValueforKey:@"country"];
    NSLog(@"country:%@ postCode: %@",country,postCode);
    
    
    NSArray* arrStr = @[@"english",@"franch",@"chinese"];
   
    NSArray* arrCapStr = [arrStr valueForKey:@"capitalizedString"];
    
    for (NSString* str  in arrCapStr) {
        NSLog(@"%@",str);
    }
    NSArray* arrCapStrLength = [arrStr valueForKeyPath:@"capitalizedString.length"];
    for (NSNumber* length  in arrCapStrLength) {
        NSLog(@"%ld",(long)length.integerValue);
    }
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
